import request from '@/utils/request'
import { AxiosPromise } from 'axios'
import { PriceForm, PriceVO } from '@/api/business/priceCharge/types'

enum Api {
  priceList = '/price/charge/list',
  priceDelete = '/price/charge/delete',
  priceBatchDelete = '/price/charge/batchDelete',
  priceAdd = '/price/charge/add',
  priceEdit = '/price/charge/edit',
  priceIssue = '/price/charge/issue',
  changeStatus = '/price/charge/changeStatus',
  priceDetail = '/price/charge/detail',
  optionSelect = '/price/charge/optionSelect',
}

// 获取列表
export const getPriceList = (data: any): AxiosPromise<any> => {
  return request({
    url: Api.priceList,
    method: 'post',
    data,
  })
}

// 删除
export const priceDelete = (data: string) => {
  return request({
    url: Api.priceDelete,
    method: 'post',
    data,
  })
}
// 批量删除
export const priceBatchDelete = (data: (string | number)[]) => {
  return request({
    url: Api.priceBatchDelete,
    method: 'post',
    data,
  })
}

// 编辑、保存
export const priceSave = (data: PriceForm) => {
  return request({
    url: data.id ? Api.priceEdit : Api.priceAdd,
    method: 'post',
    data,
  })
}

export function changeStatus(id?: string, status?: string) {
  const data = {
    id,
    status,
  }
  return request({
    url: Api.changeStatus,
    method: 'post',
    data,
  })
}

//下发
export function priceIssue(data: any) {
  return request({
    url: Api.priceIssue,
    method: 'post',
    data,
  })
}

// 详情
export const getDetail = (data) => {
  return request({
    url: Api.priceDetail,
    method: 'post',
    data,
  })
}

// 获取选择框列表
export const optionSelect = (): AxiosPromise<PriceVO[]> => {
  return request({
    url: Api.optionSelect,
    method: 'post',
    data: {},
  })
}
